﻿#pragma once
#include "AsGraphicsObject.h"
#include "AsOptions.hpp"
#include <QImage>

__AS_JY(Update 2023.1.7)
namespace AsGraphicsNamespace {

	AS_MEMBER_CLASS_DECLARATION(AsGraphicsImageViewer);

	class AS_GRAPHICS_API AsGraphicsImageViewer : public AsGraphicsObject, public AsBinder<AsGraphicsImageViewer> {
		Q_OBJECT

	public:
		explicit AsGraphicsImageViewer(QObject* parent = nullptr);
		explicit AsGraphicsImageViewer(AsGraphics* graphics, QObject* parent = nullptr);
		~AsGraphicsImageViewer();
		AsGraphicsImageViewer(const AsGraphicsImageViewer&) = delete;
		AsGraphicsImageViewer& operator=(const AsGraphicsImageViewer&) = delete;

	private:
		AS_MEMBER_CLASS(AsGraphicsImageViewer)* mp;

	public:
		void create(AsGraphics* graphics, QObject* parent = nullptr);
		void destroy();

	public:
		void setImage(QImage image, bool centerShow = true, bool sendUpdateSignal = false);
		void setImage(QPixmap image, bool centerShow = true, bool sendUpdateSignal = false) { setImage(image.toImage(), centerShow, sendUpdateSignal); }
		void setImage(QString imagePath, bool centerShow = true, bool sendUpdateSignal = false);
		void setImage(int width, int height, bool centerShow = true);
		void setImage(QSize size, bool centerShow = true);
		void removeImage();

		void fitDisplay();
		void toCenter();
		void toTopLeft();
		void centerTo(const QPointF& position);

		void toFullScreen();
		void toNormalScreen();

	public:
		bool hasImage();
		QImage getImage();
		QPoint	getMousePos();
		QColor getHorveredColor();
		double	getCurrentScale();

	public:
		void setScale(double scale);
		void setBackground(const QBrush& brush);
		void setScaleOptions(const AsOptions<double>& scaleOptions);
		void setScaleOptions(double minScale, double increasingRate, int amount);
		void setPercentTextColor(const QColor& foreground, const QColor& background);
		void setPercentTextFont(const QFont& font);
		void setPercentTextRectSize(const QSize& size);
		void setMouseDragMoveButton(Qt::MouseButton mouseButton = Qt::MouseButton::LeftButton, Qt::Key combination = (Qt::Key)0);

	public:
		void setEnable_AutoFitDisplay(bool isEnable = true);
		void setEnable_ZoomAnchorMouse(bool isEnable = true);
		void setEnable_ShowPercent(bool isEnable = true);
		void setEnable_PercentAnimation(bool isEnable = true);
		void setEnable_ZoomMoveAnimation(bool isEnable = true);
		void setEnable_MouseDragMovement(bool isEnable = true);
		void setEnable_WheelRollZoom(bool isEnable = true);
		void setEnable_Smoothness(bool isEnable = true);
		void setEnable_Antialiasing(bool isEnable = true);
		void setEnable_AutoDisplayDragImage(bool isEnable = true);
		void setEnable_FullScreen(bool isEnable = true);

	public:
		inline void setLowPerformanceMode() { setEnable_AutoFitDisplay(false); setEnable_PercentAnimation(false); setEnable_ZoomMoveAnimation(false); setEnable_Smoothness(false); }

	signals:
		void sigImageUpdate(QImage);
		void sigMousePosChanged(QPointF);
		void sigScaleChanged(double);
		void sigFileDragIn(QString);

	};

	typedef AsGraphicsImageViewer ImageViewer;

};

namespace AG = AsGraphicsNamespace;
